package com.course.redis.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

/**
 * @PROJECT_NAME: Course
 * @DESCRIPTION: 自定义注入redisson的操作bean组件
 * @Author: 涂玄武
 * @DATE: 2021/02/02 9:54
 */
@Configuration
public class RedissonConfig {

    @Autowired
    private Environment env;

    //单节点
    @Bean
    public RedissonClient client(){
        Config config=new Config();
        config.useSingleServer().setAddress(env.getProperty("redisson.url.single"))
                .setPassword("123456")
                .setTimeout(3000)
                .setRetryAttempts(3)
                .setRetryInterval(1000)
                .setPingConnectionInterval(1000)
                .setDatabase(3)
                .setKeepAlive(true);
        return Redisson.create(config);
    }


    //集群
    /*@Bean
    public RedissonClient client(){
        Config config=new Config();
        config.useClusterServers().setScanInterval(2000)
                .addNodeAddress(StringUtils.split(env.getProperty("redisson.url.cluster"),","))

                .setMasterConnectionMinimumIdleSize(10)
                .setMasterConnectionPoolSize(64)
                .setSlaveConnectionMinimumIdleSize(10)
                .setSlaveConnectionPoolSize(64)
                .setConnectTimeout(15000);

        RedissonClient client=Redisson.create(config);
        return client;
    }*/

}




























